package net.yxsoft.controller.pc.sysmgt;



import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import net.yxsoft.bean.FormDataExportFactroy;

import net.yxsoft.controller.pc.sysmgt.common.AuthController;


import net.yxsoft.kit.Helper;
import net.yxsoft.kit.PoiExporter;
import net.yxsoft.kit.QRCodeKit;
import net.yxsoft.model.formdesigner.FnFormData;
import net.yxsoft.model.infrastructure.TsUser;
import net.yxsoft.render.PoiRender;
import net.yxsoft.resource.CodeRes;
import net.yxsoft.resource.PathRes;
import net.yxsoft.service.LifecycExampleService;
import net.yxsoft.service.formdisigner.FormDataRoleService;
import net.yxsoft.service.formdisigner.FormDataService;
import net.yxsoft.service.formdisigner.FormService;
import rapid.core.Authuser;
import rapid.core.TResult;
import rapid.jfinal.Pagination;
import rapid.util.StrKit;

import java.io.File;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
* @MethodName:
* @Description:
* @param: null
* @return * @return null
* @throws
* @date 2023/8/31 14:00
* @author jhf
*/
public class FormDataController extends AuthController {

  @Inject
  FormDataService srv;
  @Inject
  FormService fsv;
  @Inject
  LifecycExampleService lsv;
  @Inject
  FormDataRoleService rsv;










  /**
  * @MethodName: index
  * @Description:
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:00
  * @author jhf
  */
  public void index() {

    render("index.html");
  }


  /**
  * @MethodName: getFormFieldByFormid
  * @Description: 根据动态表单id获取设置的字段信息
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:01
  * @author jhf
  */
  public void getFormFieldByFormid() {
    renderJson(srv.getFormFieldByFormid(getPara("formid")));
  }




  /**
  * @MethodName: getFormData
  * @Description: 获取动态表单数据
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:01
  * @author jhf
  */
  public void getFormData() {


    renderJson(srv.getFormData(getParaMap(), getLoginUser(), Pagination.by(this),getPara("cdid")));
  }

  /**
  * @MethodName: getFormDataUpdateBackup
  * @Description: 获取审核时修改数据的备份记录
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:01
  * @author jhf
  */
  public void getFormDataUpdateBackup() {

    renderJson(srv.getFormDataUpdateBackup(getParaMap(), getLoginUser(), Pagination.by(this),getPara("cdid")));
  }

 /**
 * @MethodName: add
 * @Description:
 * @param:
 * @return void
 * @throws
 * @date 2023/8/31 14:01
 * @author jhf
 */
 public void add() throws ParseException {

   String type = get("formType");
   String formid = get("formid");
   String lifenodeid = get("lifenodeid");


   renderJson(srv.add(getModel(FnFormData.class, "", true), getLoginUser(), type, formid, lifenodeid));
 }

  /**
  * @MethodName: update
  * @Description:
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:01
  * @author jhf
  */
  public void update() throws ParseException {
    renderJson(srv.update(getModel(FnFormData.class, "", true), getLoginUser(), get("formType"), get("userType"), get("formid"), get("lifenodeid")));
  }
  /**
  * @MethodName: remove
  * @Description:
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:01
  * @author jhf
  */

  public void remove() throws ParseException {
    renderJson(srv.remove(get("ids"), getLoginUser(), get("formType"), get("formid")));
  }
  /**
  * @MethodName: getFnFormByCode
  * @Description:
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:01
  * @author jhf
  */
    public void getFnFormByCode() {
      renderJson(fsv.getFnFormByCode(get("code")));
    }
  /**
  * @MethodName: getLifecycExampleNodePer
  * @Description:
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:01
  * @author jhf
  */
    public void getLifecycExampleNodePer() {
      renderJson(lsv.getLifecycExampleNodePer(get("nodeId"), getLoginUser()));
    }

  /**
  * @MethodName: getFormDataUserRole
  * @Description:
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:02
  * @author jhf
  */
    public void getFormDataUserRole() {
      renderJson(rsv.getFormDataUserRole(get("form_id"), getLoginUser()));
    }
  /**
  * @MethodName: getFormDataRole
  * @Description:
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:02
  * @author jhf
  */
    public void getFormDataRole() {

    }
  /**
  * @MethodName: audit
  * @Description:
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:02
  * @author jhf
  */
  public void audit() {
    renderJson(srv.audit(get("formId"), get("ids"), getLoginUser(), get("status"), get("opinion")));
  }
    /**
    * @MethodName: checkOperationLimits
    * @Description: 验证操作权限
    * @param:
    * @return void
    * @throws
    * @date 2023/8/31 14:02
    * @author jhf
    */
  public void checkOperationLimits() throws ParseException {
    renderJson(srv.checkOperationLimits(get("ids"), get("operation"), getLoginUser(), get("nodeid")));
  }


  /**
  * @MethodName: export
  * @Description: 导出
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:02
  * @author jhf
  */
  public void export() {

    FormDataExportFactroy _f = srv.export(getParaMap(), getLoginUser(),getPara("cdid"));

    String[] clumns = _f.getColnum();
    String[] heades = _f.getHead();
    render(PoiRender.me(_f.getData()).fileName("formdata.xls").sheetName(_f.getFilename()).headers(heades).columns(clumns).cellWidth(5000).headerRow(1));
  }

  /**
  * @MethodName: getPrintInfo
  * @Description: 打印
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:02
  * @author jhf
  */
  public void getPrintInfo() {

    FormDataExportFactroy printInfo = srv.export(getParaMap(), getLoginUser(),getPara("cdid"));
    renderJson(printInfo);
  }

  /**
  * @MethodName: getPrintBqInfo
  * @Description: 打印标签
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 14:02
  * @author jhf
  */
  public void getPrintBqInfo() {
    String id=getPara("id");

    FnFormData printInfo = FnFormData.dao.findById(id);
    renderJson(printInfo);
  }







}
